/*
   @Copyright:LeetCode
   @Author:   tjyemail
   @Problem:  http://leetcode.com/problems/unique-paths
   @Language: C++
   @Datetime: 19-07-01 16:55
   */

// C(m+n-2,min(m,n)-1)
class Solution {
public:
	int uniquePaths(int m, int n) {
		if (!m || !n) return 0;
		long k=min(m,n)-1, c=1, i=1;
		for (n+=m-2; i<=k; c=c*(n--)/(i++));
		return c;
	}
};
